<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>$Title$</title>

    <link rel="stylesheet" href="${request.contextPath}/static/ihomeStatic/css/demo.css" type="text/css">
    <link rel="stylesheet" href="${request.contextPath}/static/ihomeStatic/css/zTreeStyle/zTreeStyle.css" type="text/css">

    <script type="text/javascript" src="${request.contextPath}/static/ihomeStatic/js/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="${request.contextPath}/static/ihomeStatic/js/jquery.ztree.core.js"></script>
</head>
<body class="fixed-sidebar full-height-layout">
<div class="zTreeDemoBackground left">
    <ul id="treeDemo" class="ztree"></ul>
</div>
<div style="text-align: right;float:right;" >
    <button type="button" class="btn btn-primary" id="enter" >确定</button>
    <button type="button" class="btn btn-default" id="cancel">取消</button>
</div>
</body>





<script>
    $(function () {
       treeInit();
    });
    var _id = null;
    var _name = null;
    function treeInit(){
        var setting = {

            check: {
                enable: true
            },
            view: {
                showIcon: true
            },
            callback:{
                onClick:zTreeOnClick
            },
            data: {
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "pId"
                }
            }
        };

        function zTreeOnClick(event, treeId, treeNode, clickFlag) {
            _id = treeNode.id;
            _name = treeNode.name;
            // $("#deptId").val(_id);
        };
        $.ajax({
            url:"${request.contextPath}/userManage/department",
            success:function (data) {
                if (data!=null){
                    $.fn.zTree.init($("#treeDemo"), setting, data);
                    var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
                    treeObj.expandAll(true);//默认全部展开
                }
            },
            error:function (data) {
            }
        });
    }


    $("#enter").on('click',function () {
        var index = parent.layer.getFrameIndex(window.name);
        if(_id && _name){
            parent.$("#deptId").val(_id);
            parent.$("#deptName").val(_name);
        }
        parent.layer.close(index);//关闭当前页

    });

    $("#cancel").on('click',function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);//关闭当前页
    });
</script>
</html>
